package com.example.zoie.test;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.v7.app.ActionBarActivity;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.Date;
import java.util.Locale;


public class MainActivity extends ActionBarActivity {

    private TextView tv;
    private static Date date;
    private ImageView iv;
    private MediaPlayer player;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        this.iv = (ImageView) this.findViewById(R.id.iv);
        this.tv = (TextView) this.findViewById(R.id.tv);
        this.date = new Date(1 * 60 * 60 * 24 * 1000);
        CountDownTimer timer = new CountDownTimer(this.date.getTime(), 1000) {


            @Override
            public void onTick(long millisUntilFinished) {
                date.setTime(millisUntilFinished);
                tv.setText(String.format(Locale.getDefault(), "欢迎光临：%s:%s:%s", "" + date.getHours(), "" + date.getMinutes(), "" + date.getSeconds()));
            }

            @Override
            public void onFinish() {
                tv.setText("谢谢惠顾");
                iv.setImageResource(R.drawable.a007);
                player = MediaPlayer.create(getApplicationContext(), R.raw.audio);
                try {
                    player.start();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };

        timer.start();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (player != null) {
            player.stop();
            player.release();
        }
    }
}
